#include "GRO_Panel.h"

namespace GRO
{
    
    
    


Panel::Panel()
        : Group(Dimensions(300, 300))
        , grabInput(false)
        , keepDepth(false)
{
    _type = PANEL;
    
    PainterMap* painterMap = getPainterMap();
    if(painterMap != NULL)
    {
        painters.box = painterMap->Default_DarkShadowBoxPainter;
        painters.frame = painterMap->Default_ButtonUpPainter;
    }
}

Panel::Panel(const Dimensions& dims)
        : Group(dims)
        , grabInput(false)
        , keepDepth(false)
{
    _type = PANEL;
    
    PainterMap* painterMap = getPainterMap();
    if(painterMap != NULL)
    {
        painters.box = painterMap->Default_DarkShadowBoxPainter;
        painters.frame = painterMap->Default_ButtonUpPainter;
    }
}



Panel::~Panel()
{}

void Panel::pin(Widget* widget, int x, int y)
{
    if (widget != NULL)
    {
        widget->pos.x = pos.x + x;
        widget->pos.y = pos.y + y;
        
        widget->setGui(_gui);
        widget->setPanel(this);
        widget->setGroup(this);
        setChild(widget);
        //widget->pinned = true;

        /*if (_gui != NULL && _gui->autoApplyTheme && _gui->theme != NULL)
            widget->applyTheme(_gui->theme, true);*/

        pins.push_back(widget);
        //if (autoFitContents)
            //fitContents();
    }
}


/*void Panel::setGridSize(Uint16 rows, Uint16 columns)
{
    grid.setSize(rows, columns);
}*/

//void Panel::set(Uint16 row, Uint16 col, Widget* widget);

void Panel::pin(Widget* widget, int x, int y);

//void Panel::add(Widget* widget);

void Panel::open()
{
    _folded = false;
    if (_gui != NULL)
    {
        //_gui->panels.remove(this);
        //_gui->panels.push_back(this);
    }
}
void Panel::close()
{
    _folded = true;
}


TiXmlElement* Panel::save(TiXmlElement* parent)
{
    TiXmlElement* w = Group::save(parent);
    w->SetValue("Panel");
    
    w->SetAttribute("grabInput", grabInput);
    w->SetAttribute("keepDepth", keepDepth);
    
    return w;
}

Beacon* getBeaconByName(Widget* w, const std::string& name);


void Panel::connectBeacon(Widget* widget, Beacon* beacon, const std::string& fn_name, const std::vector<std::string>& args)
{
    Widget* w = widget;
    if(w == NULL)
        return;
    
    Beacon* b = beacon;
    if(b == NULL)
        return;
    
    if(fn_name == "open" && args.size() == 0)
    {
        b->connect<Panel, void>(this, &Panel::open);
    }
    else if(fn_name == "close" && args.size() == 0)
    {
        b->connect<Panel, void>(this, &Panel::close);
    }
    else
        Group::connectBeacon(widget, beacon, fn_name, args);
    return;
}









    
    
    
    
    
    
    
    
    
    
    
    
    
}

